#include <stdio.h>

int main(){
    int height,width,d;
    char c;
    scanf("%d %d %c %d",&height,&width,&c,&d);
    for (int i=0;i<height;i++){
        if (i==0||i==height-1){
            for (int j=0;j<width;j++){
                printf("%c",c);
            }
        }
        else{
            printf("%c",c);
            for (int j=0;j<width-2;j++){
                if (d==0)printf(" ");
                else{printf("%c",c);}
            }
            printf("%c",c);
        }
        printf("\n");
    
    }
    return 0;


}